package com.zjp.demo02251.service;

import com.zjp.demo02251.dao.CompanyUser;
import com.zjp.demo02251.dao.CompanyUserMapper;
import com.zjp.demo02251.dao.Result;
import com.zjp.demo02251.enums.ResultEnum;
import com.zjp.demo02251.exception.CompanyUserExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author james
 * @Title: CompanyUserService
 * @Package com.zjp.demo02251.service
 * @Description:
 * @date 2018/2/25  18:37
 */
@Service
public class CompanyUserService {

    @Autowired
    private CompanyUserMapper companyUserMapper;

    /**
     * @Description: 给查询所有员工格式化
     * @author james
     * @param
     * @return
     * @date 2018/2/25  18:40
    */
    public List<CompanyUser> getALLCompanyUser() throws Exception {

        List<CompanyUser> list = companyUserMapper.findAll();
        if (list == null) {
            new CompanyUserExcption(ResultEnum.UNKONW_ERROR);
        }
        return  list;
    }

    /**
     * @Description: 如果10返回还在上小学，在10-16返回还在上中学；
     * @author james
     * @date 2018/2/25  21:18
    */
    public CompanyUser getUserById(Integer id) throws Exception{
        CompanyUser companyUser = companyUserMapper.findOneById(id);
        if (companyUser.getAge()<10){
          throw  new CompanyUserExcption(ResultEnum.PRIMARY_SCHOOL);
        }else if (companyUser.getAge()>10 && companyUser.getAge()<16){
          throw  new CompanyUserExcption(ResultEnum.MIDDLE_SCHOOL);
        }
        return companyUser;
    }

}
